#include <stdio.h>

int main(void) {
    int arr[5] = {100, 200, 300, 400, 500};
    int *p1, *p2, *p3;

    p1 = arr;
    p2 = &arr[2];

    printf("pointer value, dereferenced pointer, pointer address\n");
    printf("p1 = %p, *p1 = %d, &p1 = %p\n", p1, *p1, &p1);

    p3 = p1 + 4;
    printf("\nadding an int to a pointer:\n");
    printf("p1 + 4 = %p, *(p1 + 4) = %d\n", p1 + 4, *(p1 + 4));
    
    p1++;
    printf("\nvalues after p1++:\n");
    printf("p1 = %p, *p1 = %d, &p1 = %p\n", p1, *p1, &p1);

    p2++;
    printf("\nvalues after p2++:\n");
    printf("p2 = %p, *p2 = %d, &p2 = %p\n", p2, *p2, &p2);
    
    --p1;
    --p2;
    printf("\nPointers reset to original values:\n");
    printf("p1 = %p, p2 = %p\n", p1 ,p2);

    printf("\nsubstacting one pointer from another:\n");
    printf("p2 = %p, p1 = %p, p2 - p1 = %td\n", p2, p1, p2 - p1);

    printf("\nsubstacting an int form a pointer:\n");
    printf("p3 = %p, p3 - 2 = %p\n", p3, p3 - 2);

    return 0;
}
